/**
 *
 */
package com.smart.common.enums;

import com.smart.common.exception.BusinessException;

/**
 * @author zhanghong
 */
public enum ErrorCode {
    /**
     *
     */
    SUCCESS("200", "成功"),
    ERR_REMOTE_INVOKE("500", "远程调用错误"),
    INTER_ERR("500", "服务器内部错误"),
    UN_CATCH_EXCEPTION("1000001", "未捕获的错误, 请联系管理员"),
    PARAM_ERROR("1000002", "参数错误"),
    NET_ERR("1000003", "网络延迟，请稍后重试"),
    USER_OR_PWD_INVALID("1000004", "账号或者密码错误"),

    NOT_LOGIN("5000000", "未登录"),
    LOGIN_INVALID("9999999", "登录状态已失效，请重新登录。"),
    ACCOUNT_NOT_EXIST_ERROR("5000001", "用户名不存在"),
    PASSWORD_ERROR("5000001", "密码输入错误，若忘记密码请联系建委平台管理员进行修改"),
    GUAN_LI_NOT_LOGIN_ERROR("5000002", "管理平台未登录"),

    EXIST_BIND_ROLE_ERR("6000001", "存在绑定的角色，不可删除"),
    EXIST_BIND_USER_ERR("6000002", "存在绑定的用户，不可删除"),
    ADMIN_IS_EXIST("6000003", "该账号已存在"),
    ROLE_IS_EXIST("6000004", "该角色名称已存在"),
    ;
    private String code;
    private String msg;

    private ErrorCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static ErrorCode getByCode(String code) {
        for (ErrorCode errorCode : values()) {
            if (errorCode.getCode().equals(code)) {
                return errorCode;
            }
        }
        throw new BusinessException(UN_CATCH_EXCEPTION);
    }


}
